package com.example.basic_components.AlertDialog

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.*
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp

@Composable
fun SimpleDemo() {
    var openDialog = remember { mutableStateOf(false) }
    Box(
        contentAlignment = Alignment.Center,
        modifier = Modifier.fillMaxSize()
    ) {
        Button(
            onClick = { openDialog.value = true}
        ) {
            Text(text = "tanchuang")
            if (openDialog.value) {
                AlertDialog(
                    onDismissRequest = {
                        // 当用户点击对话框以外的地方或者按下系统返回键将会执行的代码
                        openDialog.value = false
                    },
                    title = {
                        Text(
                            text = "开启位置服务",
                            fontWeight = FontWeight.W700,
                            style = MaterialTheme.typography.h6
                        )
                    },
                    text = {
                        Text(
                            text = "这将意味着，我们会给您提供精准的位置服务，并且您将接受关于您订阅的位置信息",
                            fontSize = 16.sp
                        )
                    },
                    confirmButton = {
                        TextButton(
                            onClick = {
                                openDialog.value = false
                            },
                        ) {
                            Text(
                                "确认",
                                fontWeight = FontWeight.W700,
                                style = MaterialTheme.typography.button
                            )
                        }
                    },
                    dismissButton = {
                        TextButton(
                            onClick = {
                                openDialog.value = false
                            }
                        ) {
                            Text(
                                "取消",
                                fontWeight = FontWeight.W700,
                                style = MaterialTheme.typography.button
                            )
                        }
                    }
                )
            }
        }
    }
}


